package org.jmresler.sakila.batch.services;

import jakarta.mail.MessagingException;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

@Slf4j
@SpringBootTest
class EmailServiceTest {

    /*
      There's no *good* way to test an email other than to confirm it's been sent without errors.
      Granted this is not an end to end test but it confirm some things.

      The problem with testing an email end to end is that even retrieving emails from the mail server
      may experience problems in delays of the receipt of a correctly sent email, multiple emails with the
      same subject line and there are more.

      We'll have to settle for this test right now.
     */

    @Autowired
    protected EmailService emailService;

    @Value("${spring.mail.properties.path-to-attachment}")
    private String pathToAttachment;

    @Test
    void contextLoads() {

        log.info("Path> {}", pathToAttachment);
        try {
            emailService.sendMessageWithAttachment(pathToAttachment);
        } catch (MessagingException e) {
            log.error("Error occurred sending email!", e);
        }
    }
}